<?php
App::uses("Controller", "Controller");
class AppController extends Controller {
	var $title = "Welcom to";
	public $view   = 'Theme';
    public $theme = 'default';
	var $controllerName = "Quản lý";
	var $action_array = array(
			"index"			=> "Danh sách",
			"view"			=> "Chi tiết",
			"admin_index"	=> "Danh sách bản ghi",
			"admin_add"		=> "Thêm mới bản ghi",
			"admin_view"	=> "Chi tiết bản ghi",
			"admin_edit"	=> "Cập nhật bản ghi",
			//ACL
			"admin_user_permissions" => "Phân quyền người dùng",
			"admin_role_permissions" => "Phân quyền nhóm người dùng",
			"admin_synchronize" => "Đồng bộ",
			"admin_get_user_controller_permission" =>""
		);

	public $components = array(
		// "Comm",
		"Paginator",
		"Session",
		//"DebugKit.Toolbar",
		"Acl",
		"RequestHandler",
        "Auth" => array(
            "loginRedirect" => array("admin"=>true,"controller" => "users", "action" => "index"),
            "logoutRedirect" => array("controller" => "users", "action" => "login"),
			"authError" => "You must be logged in to view this page.",
			"loginError" => "Invalid Username or Password entered, please try again.",
			"authorize" => array(
                "Actions" => array("actionPath" => "controllers")
            )
        ));
	public $helpers = array("Session","Js","I18n.I18n");
	public function beforeFilter() {
		parent::beforeFilter();
        if(isset($this->request->params["admin"]) && $this->request->params["admin"] == true){
			$this->layout = "admin";
        }
        //function
        $this->loadModel("Menu");
        $list_menus = $this->Menu->find("all");
        $this->set(compact("list_menus"));

        $this->set("title",$this->title);
        $tmpactionName = "";
        if(isset($this->action_array[$this->request->action])){
			$tmpactionName = $this->action_array[$this->request->action];
        }
        $this->set("actionName",$tmpactionName);
        $this->set("controllerName",$this->controllerName);
        $this->Auth->allow("admin_login","index","view","home");
    }
	// public function isAuthorized($user) {
	//		return false;
	// }
}
